package com.pe1n.yangtaopai.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.pe1n.yangtaopai.R;
import com.pe1n.yangtaopai.bean.DetailBean;
import com.pe1n.yangtaopai.bean.ProdsBean;
import com.pe1n.yangtaopai.page.detail.view.activity.DetailActivity;

import java.util.List;

/**
 * Created by Administrator on 2016/11/26.
 */

public class MyActivityItenOneItemRecyclerAdapter extends RecyclerView.Adapter<MyActivityItenOneItemRecyclerAdapter.MyViewHolder> {
    private Context mContent;
    private List<ProdsBean> intemOneListBean;

    public MyActivityItenOneItemRecyclerAdapter(Context mContent, List<ProdsBean> intemOneListBean) {
        this.mContent = mContent;
        this.intemOneListBean = intemOneListBean;
    }

    @Override
    public int getItemCount() {
        return intemOneListBean.size();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContent).inflate(R.layout.item_list_one_header_activity_layout, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        ProdsBean prodsBean = intemOneListBean.get(position);
        String urlString = prodsBean.getProdImage();
        Glide.with(mContent)
                .load(urlString)
                .placeholder(R.drawable.place_holder)
                .into(holder.imageView);
        holder.textView.setText(prodsBean.getProdName());
        holder.textViewNext.setText( "¥"+prodsBean.getProdPrice());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


            }
        });
        holder.textViewNext.setText("¥" + prodsBean.getProdPrice());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent  = new Intent(mContent, DetailActivity.class);
                intent.putExtra("id",Integer.parseInt(intemOneListBean.get(position).getProdId()));
                intent.putExtra("name",intemOneListBean.get(position).getProdName());
                mContent.startActivity(intent);
            }
        });
    }


    class MyViewHolder extends RecyclerView.ViewHolder {
        private ImageView imageView;
        private TextView textView;
        private TextView textViewNext;
        private LinearLayout lineatlayout;

        public MyViewHolder(View itemView) {
            super(itemView);
            imageView= (ImageView) itemView.findViewById(R.id.imageview_item_list_one_avtivity);
            textView= (TextView) itemView.findViewById(R.id.textview_item_list_one_activity);
            textViewNext= (TextView) itemView.findViewById(R.id.textview_item_list_nextone_activity);
            lineatlayout= (LinearLayout) itemView.findViewById(R.id.item_list_four_Lineatlayout);


        }
    }
}
